<template>
  <el-container class="home_box">
    <el-header>
      <div>
        <img src="../assets/logo.png" alt="">
        <span>某某公司电商后台管理系统</span>
      </div>
      <el-button type="warning" @click="logout">退出登录</el-button>
    </el-header>
    <el-container>
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <div class="toggle_menu" @click="changeCollapse">|||</div>
        <el-menu
          default-active="2"
          class="el-menu-vertical-demo"
          background-color="#34343e"
          text-color="#fff"
          active-text-color="#6599d5" unique-opened
          :collapse="isCollapse"
          :collapse-transition=false
          :router=true>
          <el-submenu :index="item.id + ''" v-for="item in menulist" :key="item.id">
            <template slot="title" >
              <i :class="icons[item.id]"></i>
              <span>{{item.authName}}</span>
            </template>
            <el-menu-item :index="subItem.path" v-for="subItem in item.children" :key="subItem.id">
              <i class="el-icon-menu"></i>
              <span>{{subItem.authName}}</span>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
  export default {
    data () {
      return {
        menulist:[],
        icons:{
          '125':'el-icon-user-solid',
          '103':'el-icon-s-check',
          '101':'el-icon-s-goods',
          '102':'el-icon-s-order',
          '145':'el-icon-s-data'
        },
        isCollapse:true
      }
    },
    created () {
      this.getMenuList()
    },
    methods:{
      logout () {
        window.sessionStorage.clear()
        this.$router.push('/login')
      },
      async getMenuList () {
        const { data : res } = await this.$http.get('menus')
        if(res.meta.status !== 200) return this.$message.error('获取菜单列表失败')
        this.menulist = res.data
      },
      changeCollapse () {
        this.isCollapse = !this.isCollapse
      }
    }
  }
</script>
<style lang="less">
  .home_box{
    height: 100%;
  }
  .el-header{
    width: 100%;
    background: #33343d;
    display: flex;
    justify-content: space-between;
    color: #fff;
    align-items: center;
    padding: 0;
    >div{
      display: flex;
      align-items: center;
      span{
        margin-left: 20px;
      }
      img{
        width: 60px;
      }
    }
  }
  .el-button{
    margin: 10px 0;
  }
  .el-aside{
    background-color: #33343d;
    .el-menu{
      border-right: none;
    }
    .toggle_menu{
      background: #425460;
      color: #fff;
      display: flex;
      justify-content: center;
      cursor: pointer;
      padding: 5px 0;
      align-items: center;
    }
  }
</style>
